from item import Item
from display_window import Menu, Alert
from inventory_item import Seeds
import imagecache

# People are just items. This is a societal comment.
class SeedSeller(Item):
    def __init__(self):
        pass
    
    def walkable(self):
        return False
    
    def get_image(self):
        return imagecache.get_image('shopkeeper')
    
    def interact(self, game):
        seed_prices = {'tomato': 20, 'potato': 30, 'corn': 40}
        seeds = ['tomato', 'potato', 'corn']
        
        # necessary, as lambda'ing the buy function directly doesn't resolve till too late, and a is the same for all of them
        def lambda_buy(plant_name):
            def buy(plant_name):
                seeds = Seeds(plant_name)
                if game.player.has_money(seed_prices[plant_name]):
                    game.player.inventory.add(seeds)
                    game.player.add_money(-seed_prices[plant_name])
                else:
                    #Alert
                    pass
            return lambda: buy(plant_name)
        
        contents = list()
        for a in seeds:
            contents.append((a, None, lambda_buy(a)))
        contents.append(("Exit", None, None))
            
        Menu(game.screen, contents, game.get_display).show()
    